<template>
    <div>

        <Form :label-width="100" inline>
            <FormItem label="行政区划代码">
                <area-linkage :areaCode.sync="queryParam.ssca0043" :countyDisable=false :streetDisable=false
                              :communityDisable=false></area-linkage>
            </FormItem>
            <FormItem label="用户名称">
                <Input v-model="queryParam.name" placeholder="请输入用户名" style="width:160px"/>
            </FormItem>
            <FormItem label="用户账号">
                <Input v-model="queryParam.login_name" placeholder="请输入登录帐号" style="width:160px"/>
            </FormItem>
            <FormItem label="移动号码">
                <Input v-model="queryParam.mobile" placeholder="请输入移动号码" style="width:160px"/>
            </FormItem>
            <FormItem label="是否短信校验">
                <dictSelect :sel_val='queryParam.is_need_msg' dictCode="yesorno" :bindData.sync="queryParam.is_need_msg"
                            style="width: 150px" placeholder="请选择是否短信校验" clearable/>
            </FormItem>
            <FormItem label="是否允许登录">
                <dictSelect :sel_val='queryParam.login_flag' dictCode="yesorno" :bindData.sync="queryParam.login_flag"
                            style="width: 150px" placeholder="请选择是否允许登录" clearable/>
            </FormItem>
            <Row class="button_row">
                <span style="float: left;">
                <Button type="primary" class="step-item" @click="synchronous()">同步</Button>
                <Button type="primary" icon="ios-cloud-download-outline" @click="exportE" class="button_item_left">导出
                </Button>
                </span>
                <span style="float: right;">
                      <Button type="primary" @click="searchQuery">查询</Button>
                <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
                </span>
            </Row>
        </Form>
        <Modal v-model="visible" :title="title" width="600" style="position:relative;">
            <Form ref="formData" :model="formData" :label-width="150" :disabled="disableSubmit">
                <FormItem label="行政区划代码">
                    <Input v-model="formData.area_code" style="width: 200px"></Input>
                </FormItem>
                <FormItem label="行政区划名称">
                    <Input v-model="formData.azaa0002" style="width: 200px"></Input>
                </FormItem>
                <FormItem label="用户账号">
                    <Input v-model="formData.login_name" style="width: 200px"/>
                </FormItem>
                <FormItem label="用户姓名">
                    <Input v-model="formData.name" style="width: 200px"/>
                </FormItem>
                <FormItem label="角色名称">
                    <Input type="textarea" v-model="formData.role_name" style="width: 200px" size="large"></Input>
                </FormItem>
                <FormItem label="移动号码">
                    <Input v-model="formData.mobile" style="width: 200px"/>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="visible = false">取消</Button>
                <template v-if="!disableSubmit">
                    <Button type="primary" size="large" @click="handleSubmit('formData')">确定</Button>
                </template>
            </div>
        </Modal>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       :data="tableData">
                <vxe-table-column field="area_code" title="行政区划代码" align="center" fixed="left"/>
                <vxe-table-column field="azaa0002" title="行政区划名称" align="center" fixed="left"/>
                <vxe-table-column field="login_name" title="用户账号" align="center" fixed="left"/>
                <vxe-table-column field="name" title="用户名称" align="center"/>
                <vxe-table-column field="role_name" title="角色名称" align="center" width="340"/>
                <vxe-table-column field="login_flag_name" title="是否允许登录" align="center" width="120"/>
                <vxe-table-column field="mobile" title="移动号码" align="center" width="130">
                    <template v-slot="{row}">
                        <Span v-if="row.mobile==undefined" style="color: red">未录入手机号码</Span>
                        <Span v-else>{{row.mobile}}</Span>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="is_need_msg_name" title="是否短信校验" align="center" width="120">
                <template v-slot="{row}">
                    <Span v-if="row.mobile==undefined || row.mobile==''" style="color: red"></Span>
                    <Span v-else>{{row.is_need_msg_name}}</Span>
                </template>
            </vxe-table-column>
                <vxe-table-column title="操作" align="center" fixed="right" width="180">
                    <template #default="{row}">
                        <Button type="error" v-if="row.is_need_msg=='1' && row.mobile!=undefined && row.mobile!=''" @click="editSendMessage(row)">取消短信校验</Button>
                        <Button type="success" v-if="row.is_need_msg=='0' && row.mobile!=undefined && row.mobile!=''" @click="editSendMessage(row)">添加短信校验</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'

    export default {
        mixins: [CommonMixin],
        components: {
            dictSelect,
        },
        data() {
            return {
                tableData: [],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/extSysUser/getPageListForUser",
                    delete: "/api/ac/subsistence/extSysUser/deleteData"
                },
                formData: {},
                queryParam: {},
                visible: false,
                dataCount: 0,
                pageSize: 10,
                modal: false,
                title: "",
                disableSubmit: false,
                exportFileName: "用户导出"
            }
        },
        methods: {
            // 添加/取消 短信校验
            editSendMessage(row) {
                let that = this;
                postAction("/api/ac/subsistence/extSysUser/updateSendMessage", row).then((res) => {
                    if (res.data.errcode == '0') {
                        this.$Message.success(res.data.data.Message);
                    } else {
                        this.$Message.error("修改失败, 请联系管理员");
                    }
                }).finally(() => {
                    this.loadData();
                });
            },
            synchronous() {
                let that = this;
                that.Loading = true;
                let url = "/api/ac/subsistence/extSysUser/createSynchronous";
                postAction(url, "").then((res) => {
                    this.$Message.success(res.data.data.Message);
                }).finally(() => {
                    this.modalFormOk();
                    that.Loading = false;
                });
            },
            exportE() {
                this.url.exportExcel = "/api/ac/subsistence/extSysUser/export";
                this.exportExcel();
            },
        },
        created() {
            this.loadData();
        },
        watch: {}
    }
</script>
<style scoped>
    /deep/ .ivu-form-item-error-tip {
        display: none;
    }



    .itemStyle {
        width: 180px
    }

    .head-img1 {
        height: 200px;
        width: 250px;
        margin-top: 15px;
    }

    .head-img {
        height: 200px;
        width: 250px;
    }

    .imgBackColor {
        background-color: WhiteSmoke;
        height: 250px;
    }

    .positiveTDiv {
        height: 240px;
        width: 75px;
        line-height: 240px;
        background-color: #7CCD7C;
        margin-bottom: 10px;
        color: white;
        font-size: 14px;
        font-weight: 700;
    }
</style>
